﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace MainJumpFleet.TempObjects
{
    public class Bullet
    {
        private Vector2 position;
        public Vector2 velocity;
        public Rectangle Bounds;
        private float rotation;
        Texture2D texture;
        SpriteFont font;
        OakEngine.Camera.Oak_Camera camera;
        private bool m_bisAlive;
        public float bulletSpeed;
        public float Speed { get { return bulletSpeed; } set { bulletSpeed = value; } }

        JumpFleetGameLib.xSprite.StaticSprite sprite;

        #region PROPERTIES

        public bool IsAlive
        {
            get { return m_bisAlive; }

            set
            {
                m_bisAlive = value;
                sprite.Visible = value;
            }
        }

        public Vector2 Position
        {
            get { return position; }

            set
            {
                position = value;
                sprite.DrawPosition = value;
            }
        }

        public float Rotation
        {
            get { return rotation; }

            set
            {
                rotation = value;
                sprite.RotationAmount = value;
            }
        }


        #endregion

        #region Constructor


        public Bullet(Texture2D tex, SpriteFont font, Vector2 position, Vector2 velocity, float rot)
        {
            texture = tex;
            this.font = font;
            int width = tex.Width;
            int height = tex.Height;
            this.position = position;
            this.velocity = velocity;
            this.rotation = rot;
            m_bisAlive = true;
            bulletSpeed = 450.0f;
        }


        public Bullet(Texture2D tex, SpriteFont font, Vector2 position, Vector2 velocity, float rot, ref OakEngine.Camera.Oak_Camera cam)
        {
            texture = tex;
            this.font = font;
            int width = tex.Width;
            int height = tex.Height;
            this.position = position;
            this.velocity = velocity;
            this.rotation = rot;
            m_bisAlive = true;
            camera = cam;
            bulletSpeed = 450.0f;

        }

        /*
        public Bullet(Texture2D tex, Vector2 position, Vector2 velocity, float rot, ref OakEngine.Camera.Oak_Camera cam)
        {
            texture = tex;
            camera = cam;
            int width = tex.Width;
            int height = tex.Height;
            this.position = position;
            this.velocity = velocity;
            this.roation = rot;
            m_bisAlive = true;
            bulletSpeed = 450.0f;

        }
         */

        public Bullet(JumpFleetGameLib.xSprite.StaticSprite sprite, Vector2 position, Vector2 velocity, float rot, ref OakEngine.Camera.Oak_Camera cam)
        {
            this.sprite = sprite;
            camera = cam;
            int width = sprite.Width;
            int height = sprite.Height;
            this.Position = position;
            this.velocity = velocity;
            this.Rotation = rot;
            IsAlive = true;
            bulletSpeed = 250.0f;

        }

        #endregion

        #region Update & Render

        public void Update(float dt)
        {
            // position.X += velocity.X * bulletSpeed * dt;
            // position.Y += velocity.Y * bulletSpeed * dt;
            Position = new Vector2(Position.X + velocity.X * bulletSpeed * dt, Position.Y + velocity.Y * bulletSpeed * dt);
            Bounds = new Rectangle((int)Position.X, (int)Position.Y, sprite.Width, sprite.Height);
        }

        public void Render(SpriteBatch batch)
        {
            // batch.Draw(texture, position - camera.CameraPosition, null, Color.White, rotation, new Vector2(texture.Width * 0.5f, texture.Height * 0.5f), 2, SpriteEffects.None, 0.5f);
            //batch.DrawString(font, "Position: " + position.ToString(), this.position + new Vector2(50, 0) - camera.CameraPosition, Color.Red);
            //batch.DrawString(font, "Velocity: " + velocity.ToString(), this.position + new Vector2(50, 50) - camera.CameraPosition, Color.Red);
        }
        #endregion

        public bool Intersect(Rectangle rec)
        {
            if (Bounds.Intersects(rec))
                return true;

            return false;
        }


    }
}
